//
//  SSEmoticonPageView.swift
//  SSSina
//
//  Created by ss on 2017/7/10.
//  Copyright © 2017年 ss. All rights reserved.
//

import UIKit
// cell可重用标识符
private let SSEmoticonPageViewCellId = "SSEmoticonPageViewCellId"
class SSEmoticonPageView: UICollectionView {
    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        // layout
        let flowLayout = UICollectionViewFlowLayout()
        // 设置垂直和水瓶间距
        flowLayout.minimumLineSpacing = 0
        flowLayout.minimumInteritemSpacing = 0
        // 滚动方向
        flowLayout.scrollDirection = .horizontal
        super.init(frame: frame, collectionViewLayout: flowLayout)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 设置视图
    private func setupUI(){
        backgroundColor = randomColor()
        dataSource = self
        register(SSEmoticonPageViewCell.self, forCellWithReuseIdentifier: SSEmoticonPageViewCellId)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        // 获取layout
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        // 设置itemSize
        layout.itemSize = self.frame.size
    }
    
}
//MARK: - UICollectionViewDataSource
extension SSEmoticonPageView: UICollectionViewDataSource{
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 4
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 3
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SSEmoticonPageViewCellId, for: indexPath) as! SSEmoticonPageViewCell
        cell.indexPath = indexPath
        return cell
    }
}

